# 第一阶段：构建阶段
FROM iregistry.baidu-int.com/baidu-base/java-builder:11-maven-alpine3.16 AS builder

# 设置工作目录
WORKDIR /portal-server

RUN mkdir -p /root/.m2 && \
    echo '<?xml version="1.0" encoding="UTF-8"?>' > /root/.m2/settings.xml && \
    echo '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"' >> /root/.m2/settings.xml && \
    echo '          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' >> /root/.m2/settings.xml && \
    echo '          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">' >> /root/.m2/settings.xml && \
    echo '  <mirrors>' >> /root/.m2/settings.xml && \
    echo '    <mirror>' >> /root/.m2/settings.xml && \
    echo '      <id>baidu-nexus-snapshot</id>' >> /root/.m2/settings.xml && \
    echo '      <url>http://maven.baidu-int.com/nexus/content/groups/public-snapshots</url>' >> /root/.m2/settings.xml && \
    echo '      <mirrorOf>public-snapshots</mirrorOf>' >> /root/.m2/settings.xml && \
    echo '    </mirror>' >> /root/.m2/settings.xml && \
    echo '    <mirror>' >> /root/.m2/settings.xml && \
    echo '      <id>baidu-nexus</id>' >> /root/.m2/settings.xml && \
    echo '      <url>http://maven.baidu-int.com/nexus/content/groups/public</url>' >> /root/.m2/settings.xml && \
    echo '      <mirrorOf>*</mirrorOf>' >> /root/.m2/settings.xml && \
    echo '    </mirror>' >> /root/.m2/settings.xml && \
    echo '  </mirrors>' >> /root/.m2/settings.xml && \
    echo '</settings>' >> /root/.m2/settings.xml

# 复制 Maven 项目文件
COPY pom.xml .
COPY src ./src

# 执行 Maven 编译和打包

RUN mvn clean package -DskipTests

# 第二阶段：运行阶段，使用轻量级镜像运行构建产物
FROM iregistry.baidu-int.com/baidu-base/openjdk:8-alpine3.19

ADD ./output/portal-server-1.0.jar portal-server.jar


# 暴露应用程序的端口
EXPOSE 8008

# 运行应用程序
ENTRYPOINT ["java", "-jar", "portal-server.jar"]

